home *** CD-ROM | disk | FTP | other *** search
- *****************
- The Stack Display
- *****************
-
- In HeliOS you have a continuous on-screen display of the stack in a strip
- along the top of the Interpreter display window.
-
- The top ten stack items are displayed, with the top-of-stack item shown in
- red, and the number of items on the stack shown in yellow.
-
- This stack display is replaced by the DEBUG control panel when you enter
- "debug" mode.
-
- The stack display always shows the current stack status, and is very useful
- for beginners who are unsure of how the stack works.
-
- In fact, this feature of HeliOS is ENTIRELY for the benefit of beginners,
- because once you are experienced with stack manipulation you will rarely
- need a full graphical display such as this.
-
- In fact, the rest of this text on the stack is aimed at the beginner......
-
- The biggest single difficulty the beginner with a stack-oriented language
- faces seems always to lie in grasping how the stack works. The first
- thing any commentator or reviewer always points out about Forth is the
- difficulty of using the stack and reverse Polish notation, and in general
- there is a negative "fear" of this topic in most beginner's minds before
- they even get started.
-
- Perhaps you too have been assailed by doubts about these matters?
-
- This initial confusion and "fear" can present quite unnecessary and even
- insurmountable problems in some cases, which is a great pity because the
- stack really is very easy to understand once you can see exactly what
- is happening. It is actually utterly trivial and simple, so forget all
- jargon and complicated explanations you have read and learn by practise.
-
- HeliOS is unashamedly dedicated to helping the beginner rather than
- presenting a highly "difficult" image to impress by sheer complication as
- many languages do. Programming can be easy and pleasurable, and we hope
- you will appreciate how easy the stack can be by using the excellent
- stack display included just for your benefit!
-
- Many texts on Forth, when trying to describe stack concepts and "reverse
- Polish notation", struggle to explain the stack with all manner of diagrams
- and analogies. The fact is that without anything concrete to see, and
- only abstract highly technical explanations to help, often the poor student
- is left bemused. Just looking at a string of confusing stack operators on
- the page of a book, accompanied by an often frightening and complicated
- explanation is not at all helpful.
-
- Many would-be Forth programmers give up at this stage, but in fact the use
- of a stack to pass parameters is very simple if you approach it with an
- open mind and a freedom from all the usual associated jargon.
-
- Forget all the talk of "reverse Polish notation" which you might have read,
- and simply sit at your Amiga and experiment with the stack for yourself.
-
- Just type in a few numbers and observe the stack display. Use a few of
- the simple arithmetic operators such as "+" or "-" and watch what happens
- to the numbers on the stack.
-
- Use a few of the simple stack operators like DUP and ROT and watch how
- they affect numbers on the stack. Try to build up just a small repertoire
- of commands which you understand before trying to learn too many of the
- more complex operators.
-
- Spend just a few hours "playing" wiuth the stack and once you are used to
- seeing a "concrete" display of what is happening, the use of the stack will
- become very clear.
-
-
- **************************
- HeliOS Stack Control Words
- **************************
-
- There seem to be an awful lot of these, but they are very easy to use
- and learn, and are very, very important in the production of efficient
- and readable HeliOS code.
-
- Use these words to MINIMISE THE NUMBER OF STACK MANIPULATION WORDS which
- you employ.
-
- DO NOT write long strings of DUPs and SWAPs and ROTs, as this produces
- grotesquely unreadable code and is horrifyingly inefficient, since these
- words contribute exactly nothing to getting the logical task done, being
- merely an undesirable OVERHEAD of any Forth based system.
-
- So....always use ONE word if possible instead of several.
-
- N.B.
-
- ALL the HeliOS stack management words are machine coded for speed, as
- distinct from most Forth systems, where words like ROLL, for example, if
- they are present at all, are often coded in slower high-level Forth.
-
- This has rightly led to their use being generally condemned as grossly
- inefficient in terms of CPU time, but in HeliOS all the stack management
- words are machine coded and ultra efficient, so use the words which give
- you simplest operation.
-
- The "less stack control words used the better" is a good rule!
-
- "Keep the stack small" is another good rule!
-
- If your program stack gets very big you should probably be doing things
- another way, such as using named variables. It is not "macho" or clever
- to "think" you can handle huge stacks with complicated stack control code.
- This sort of thing is merely going to land you in trouble with buggy code
- which is hard to read and change, so if you have more than three or four
- items on the stack, think carefully about why!
-
- Good HeliOS programming starts (and often stops!) here, so really get to
- know as many stack control words as possible so that their use becomes
- second nature.
-
- Set yourself up a dummy stack in Interactive mode and play with the stack
- control words you are not sure of until you see clearly how they work.
-
- ***************************************************************************
-